var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var util = require('util');
var signServletAgent = require('./servers/getSignServletAgent.js');
var vCodeAgent = require('./servers/verficationCodeAgent.js');
var getNumServletAgent = require('./servers/getNumServletAgent.js');
var youtouAgent = require('./servers/youtuServletAgent.js');
var hengFengAgent = require('./servers/hengFengAgent.js');
var kexinBarbrecordAgent = require('./servers/kexinbadrecordAgent.js');
var kexinBrokenAgent = require('./servers/kexinBrokenAgent.js');
var dataAgent = require('./servers/getDateAgent.js');
var smsSeverAgent = require('./servers/sendSMSServletAgent.js');
var configAgent = require('./servers/getConfigAgent.js');
var monidata = require('./servers/monidata.js');

// 创建 application/x-www-form-urlencoded 编码解析
var urlencodedParser = bodyParser.urlencoded({
    extended: false
});

/*-----------html--------*/
app.get('/dist/faceDetect/faceDetect.html', function(req, res) {
    res.sendFile(__dirname + "/dist/faceDetect/faceDetect.html");
});
app.get('/dist/faceDetect/loding.html', function(req, res) {
    res.sendFile(__dirname + "/dist/faceDetect/loding.html");
});
app.get('/dist/faceDetect/contract.html', function(req, res) {
    res.sendFile(__dirname + "/dist/faceDetect/contract.html");
});
app.get('/dist/faceDetect/developing.html', function(req, res) {
    res.sendFile(__dirname + "/dist/faceDetect/developing.html");
});
app.get('/dist/faceDetect/fail.html', function(req, res) {
    res.sendFile(__dirname + "/dist/faceDetect/fail.html");
});
app.get('/dist/faceDetect/info.html', function(req, res) {
    res.sendFile(__dirname + "/dist/faceDetect/info.html");
});
app.get('/dist/faceDetect/taskList.html', function(req, res) {
    res.sendFile(__dirname + "/dist/faceDetect/taskList.html");
});
app.get('/dist/faceDetect/taskList.html', function(req, res) {
    res.sendFile(__dirname + "/dist/faceDetect/taskList.html");
});

/*---------js----------*/
app.get('/dist/js/faceDetect/urlValue.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/faceDetect/urlValue.js");
});
app.get('/dist/js/faceDetect/common.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/faceDetect/common.js");
});
app.get('/dist/js/faceDetect/faceIndex.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/faceDetect/faceIndex.min.js");
});
app.get('/dist/js/faceDetect/loding.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/faceDetect/loding.js");
});
app.get('/dist/js/faceDetect/jquery-weui.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/faceDetect/jquery-weui.min.js");
});
app.get('/dist/js/faceDetect/modal.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/faceDetect/modal.js");
});
app.get('/dist/js/faceDetect/jquery-extend.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/faceDetect/jquery-extend.js");
});
app.get('/dist/js/faceDetect/toptip.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/faceDetect/toptip.js");
});
app.get('/dist/js/faceDetect/jquery-weui.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/faceDetect/jquery-weui.js");
});
app.get('/dist/js/project/urlValue.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/project/urlValue.js");
});




app.get('/dist/js/libs/jquery-1.11.1.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/libs/jquery-1.11.1.min.js");
});

app.get('/dist/js/libs/jquery.mobile-1.4.5.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/libs/jquery.mobile-1.4.5.min.js");
});

app.get('/dist/js/libs/jquery-3.0.0.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/libs/jquery-3.0.0.min.js");
});
app.get('/dist/js/libs/iscroll5.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/libs/iscroll5.js");
});
app.get('/dist/js/faceDetect/fail.min.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/faceDetect/fail.min.js");
});
app.get('/dist/js/faceDetect/contract.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/faceDetect/contract.js");
});
app.get('/dist/js/libs/iscroll.js', function(req, res) {
    res.sendFile(__dirname + "/dist/js/libs/iscroll.js");
});





/*------css----------*/
app.get('/dist/css/faceDetect/faceMain.css', function(req, res) {
    res.sendFile(__dirname + "/dist/css/faceDetect/faceMain.css");
});
app.get('/dist/css/faceDetect/jquery-weui.css', function(req, res) {
    res.sendFile(__dirname + "/dist/css/faceDetect/jquery-weui.css");
});
app.get('/dist/css/faceDetect/contract.css', function(req, res) {
    res.sendFile(__dirname + "/dist/css/faceDetect/contract.css");
});




/*-------img----------*/
app.get('/dist/img/faceDetect/saomiao.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/saomiao.png");
});
app.get('/dist/img/faceDetect/lansebeijing_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/lansebeijing_icon.png");
});
app.get('/dist/img/faceDetect/demo.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/demo.png");
});
app.get('/dist/img/faceDetect/demo2_0.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/demo2_0.png");
});
app.get('/dist/img/faceDetect/demo3.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/demo3.png");
});
app.get('/dist/img/faceDetect/demo2_1.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/demo2_1.png");
});
app.get('/dist/img/faceDetect/demo2_2.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/demo2_2.png");
});
app.get('/dist/img/faceDetect/naixindengdai_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/naixindengdai_icon.png");
});
app.get('/dist/img/ajax-loader.gif', function(req, res) {
    res.sendFile(__dirname + "/dist/img/ajax-loader.gif");
});
app.get('/dist/img/faceDetect/blue@2x.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/blue@2x.png");
});
app.get('/dist/img/faceDetect/fristBackground.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/fristBackground.png");
});
app.get('/dist/img/faceDetect/shouye_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/shouye_icon.png");
});
app.get('/dist/img/faceDetect/shouye_icon_wanjitong.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/shouye_icon_wanjitong.png");
});
app.get('/dist/img/faceDetect/shouye_icon_yonghuming.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/shouye_icon_yonghuming.png");
});
app.get('/dist/img/faceDetect/shouye_icon_mima.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/shouye_icon_mima.png");
});
app.get('/dist/img/faceDetect/zuhe_icon_46px.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/zuhe_icon_46px.png");
});
app.get('/dist/img/faceDetect/beijingtu1_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/beijingtu1_icon.png");
});
app.get('/dist/img/faceDetect/beijingtu2_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/beijingtu2_icon.png");
});
app.get('/dist/img/faceDetect/libiao_iconpx.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/libiao_iconpx.png");
});
app.get('/dist/img/faceDetect/fanhui.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/fanhui.png");
});
app.get('/dist/img/faceDetect/tmup.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/tmup.png");
});
app.get('/dist/images/faceDetect/fanhui.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/faceDetect/fanhui.png");
});
app.get('/dist/images/faceDetect/blue@2x.png', function(req, res) {
    res.sendFile(__dirname + "/dist/images/faceDetect/blue@2x.png");
});
app.get('/dist/img/faceDetect/tuichu_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/tuichu_icon.png");
});
app.get('/dist/img/faceDetect/tongxunlu_icon.png', function(req, res) {
    res.sendFile(__dirname + "/dist/img/faceDetect/tongxunlu_icon.png");
});




app.post('/wjttest/main/home', urlencodedParser, function(req, res) {
    /*    res.writeHead(200, {
            'Content-Type': 'text/html;charset=utf-8'
        }); //设置response编码为utf-8*/
    // application/json  接口返回json数据
    // charset=utf-8 解决json数据中中文乱码
    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/wjttest/main/home"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
//        res.end(data);
    });
    agentObjet.request();
    var singInData = monidata.gethomeData(req.body);
    console.log(JSON.stringify(singInData));
    res.end(JSON.stringify(singInData));
});
app.post('/wjttest/user/uppwd', urlencodedParser, function(req, res) {
    /*    res.writeHead(200, {
            'Content-Type': 'text/html;charset=utf-8'
        }); //设置response编码为utf-8*/
    // application/json  接口返回json数据
    // charset=utf-8 解决json数据中中文乱码
    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/wjttest/user/uppwd"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
//        res.end(data);
    });
    agentObjet.request();
    var singInData = monidata.getuppwd(req.body);
    console.log(JSON.stringify(singInData));
    res.end(JSON.stringify(singInData));
});


app.post('/wjttest/wx/jsapi/sign', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'application/json;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = dataAgent.getAgent({path:"/wx/jsapi/sign"}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
//        res.end(data);
    });
    agentObjet.request();
    var queryRecord = monidata.getwxquanxian(req.body);
    console.log(JSON.stringify(queryRecord));
    res.end(JSON.stringify(queryRecord));
});

app.post('/wjttest/login/in', urlencodedParser, function(req, res) {
    /*    res.writeHead(200, {
            'Content-Type': 'text/html;charset=utf-8'
        }); //设置response编码为utf-8*/
    // application/json  接口返回json数据
    // charset=utf-8 解决json数据中中文乱码
    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/login/in"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
//        res.end(data);
    });
    agentObjet.request();
    var singInData = monidata.getSingInData(req.body);
    console.log(JSON.stringify(singInData));
    res.end(JSON.stringify(singInData));
});



app.post('/wjttest/pkg/query', urlencodedParser, function(req, res) {
    /*    res.writeHead(200, {
            'Content-Type': 'text/html;charset=utf-8'
        }); //设置response编码为utf-8*/
    // application/json  接口返回json数据
    // charset=utf-8 解决json数据中中文乱码
    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/pkg/query"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
//        res.end(data);
    });
    agentObjet.request();
    var singInData = monidata.getQueryData(req.body);
    console.log(JSON.stringify(singInData));
    res.end(JSON.stringify(singInData));
});

app.post('/wjttest/pkg/log/page', urlencodedParser, function(req, res) {
    /*    res.writeHead(200, {
            'Content-Type': 'text/html;charset=utf-8'
        }); //设置response编码为utf-8*/
    // application/json  接口返回json数据
    // charset=utf-8 解决json数据中中文乱码
    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/pkg/log/page"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
//        res.end(data);
    });
    agentObjet.request();
    var singInData = monidata.getQueryRecordServlet(req.body);
    console.log(JSON.stringify(singInData));
    res.end(JSON.stringify(singInData));
});

app.post('/wjttest/pkg/log/detail', urlencodedParser, function(req, res) {
    /*    res.writeHead(200, {
            'Content-Type': 'text/html;charset=utf-8'
        }); //设置response编码为utf-8*/
    // application/json  接口返回json数据
    // charset=utf-8 解决json数据中中文乱码
    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({
        "path": "/pkg/log/detail"
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
//        res.end(data);
    });
    agentObjet.request();
    var singInData = monidata.getAccountsDetails(req.body);
    console.log(JSON.stringify(singInData));
    res.end(JSON.stringify(singInData));
});


app.post('/wjttest/liveDec/SMSSendServlet', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'application/json;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = vCodeAgent.getAgent({}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
//        res.end(data);
    });
    agentObjet.request();
});
app.post('/wjttest/wx/face/num', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'application/json;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = dataAgent.getAgent({path:"/wx/face/num"}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
    var numData = monidata.getFaceNum(req.body);
    console.log(JSON.stringify(numData));
    res.end(JSON.stringify(numData));
});
app.post('/wjttest/liveDec/YouTuDetectServlet', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'application/json;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
     var agentObjet = dataAgent.getAgent({
    }, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
//        res.end(data);
    });
    agentObjet.request();
});
app.post('/wjttest/liveDec/KexinBrokenServlet', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'application/json;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = kexinBrokenAgent.getAgent({}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
});
app.post('/wjttest/liveDec/KexinBadrecordServlet', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'application/json;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = kexinBarbrecordAgent.getAgent({}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
//        res.end(data);
    });
    agentObjet.request();
    var mndata = monidata.getkexin001(req.body);
    console.log(JSON.stringify(mndata));
    res.end(JSON.stringify(mndata));
});
app.post('/wjttest/liveDec/HengFengServlet', urlencodedParser, function(req, res) {
    res.writeHead(200, {
        'Content-Type': 'application/json;charset=utf-8'
    }); //设置response编码为utf-8
    console.log("取验证码条件" + util.inspect(req.body));
    var agentObjet = hengFengAgent.getAgent({}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        res.end(data);
    });
    agentObjet.request();
});
app.post('/wjttest/score/index', urlencodedParser, function(req, res) {
    /*    res.writeHead(200, {
            'Content-Type': 'text/html;charset=utf-8'
        }); //设置response编码为utf-8*/
    // application/json  接口返回json数据
    // charset=utf-8 解决json数据中中文乱码
    res.writeHead(200, {
        "Content-Type": "application/json;charset=utf-8"
    });
    console.log("请求条件" + util.inspect(req.body));
    //   res.end(mndata.signIn);
    var agentObjet = dataAgent.getAgent({}, req.body);
    agentObjet.on("databack", function(data) {
        console.log("datback......");
        console.log('data: ' + data);
        // res.end(data);
    });
    agentObjet.request();
    var sindex = monidata.getScoreIndex(req.body);
    console.log(JSON.stringify(sindex));
    res.end(JSON.stringify(sindex));
});




var server = app.listen(9082, function() {

    var host = server.address().address;
    var port = server.address().port;

    console.log("应用实例，访问地址为 http://%s:%s", host, port)

});
